home *** CD-ROM | disk | FTP | other *** search
- /*
- This header file can be used to implement
- your own external devices for Emu8086 -
- 8086 Microprocessor Emulator.
- Device can be written in C/C++/MS Visual C++
- (for Visual Basic use "IO.BAS" instead).
-
- Supported input / output addresses:
- 15 to 65535 (0000Fh - 0FFFFh)
-
- Version 2.12 of Emu8086 or above is required,
- check this URL for the latest version:
- http://www.emu8086.com
-
- You don't need to understand the code of this
- module, just include this file ("io.h") into your
- project, and use these functions:
-
- unsigned char READ_IO_BYTE(long lPORT_NUM)
- short int READ_IO_WORD(long lPORT_NUM)
-
- void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
- void WRITE_IO_WORD(long lPORT_NUM, short int iValue)
-
- Where:
- lPORT_NUM - is a number in range: from 15 to 65535.
- uValue - unsigned byte value to be written to a port.
- iValue - signed word value to be written to a port.
- */
-
- const char sIO_FILE[] = "EmuPort.io";
-
- unsigned char READ_IO_BYTE(long lPORT_NUM)
- {
- unsigned char tb;
-
- char buf[500];
- unsigned int ch;
-
- GetTempPath (499,buf);
-
-
- strcat(buf, sIO_FILE);
-
- FILE *fp;
-
- fp = fopen(buf,"r+");
-
- // Read byte from port:
- fseek(fp, lPORT_NUM, SEEK_SET);
- ch = fgetc(fp);
-
- fclose(fp);
-
- tb = ch;
-
- return tb;
- }
-
- short int READ_IO_WORD(long lPORT_NUM)
- {
- short int ti;
- unsigned char tb1;
- unsigned char tb2;
-
- tb1 = READ_IO_BYTE(lPORT_NUM);
- tb2 = READ_IO_BYTE(lPORT_NUM + 1);
-
- // Convert 2 bytes to a 16 bit word:
- ti = tb2;
- ti = ti << 8;
- ti = ti + tb1;
-
- return ti;
- }
-
- void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
- {
- char buf[500];
- unsigned int ch;
-
- GetTempPath (499,buf);
-
- strcat(buf, sIO_FILE);
-
- FILE *fp;
-
- fp = fopen(buf,"r+");
-
- ch = uValue;
-
- // Write byte to port:
- fseek(fp, lPORT_NUM, SEEK_SET);
- fputc(ch, fp);
-
- fclose(fp);
- }
-
- void WRITE_IO_WORD(long lPORT_NUM, short int iValue)
- {
- WRITE_IO_BYTE (lPORT_NUM, iValue & 0x00FF);
- WRITE_IO_BYTE (lPORT_NUM + 1, (iValue & 0xFF00) >> 8);
- }
-